package hust.music.action;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import hust.music.action.base.ActionBase;
import hust.music.entity.User;
import hust.music.service.UserModService;

/**
 * LoginAction
 * 
 * @author Txazo
 * @since 1.0
 */
@Controller
@Scope("session")
public class LoginAction extends ActionBase {

	private static final long serialVersionUID = 1L;

	/** 用户名 */
	private String username;
	/** 密码 */
	private String password;

	@Autowired
	private UserModService userModService;

	/**
	 * 登录处理
	 * 
	 * @return 逻辑视图
	 * @throws Exception
	 */
	public String login() throws Exception {
		if (!getUsername().equals("") && getUsername() != null
				&& getPassword() != null && !getPassword().equals("")) {
			User user = new User();
			user.setUsername(username);
			user.setAuthtoken(password);
			User login = userModService.login(user);
			if (login != null) {
				session.put("user", login);
				return SUCCESS;
			}
			return INPUT;
		}
		return INPUT;
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

}